using System;
using Sinacor.Infra.UI.Common;
using Sinacor.Infra.UI.Security.Services;
using Sinacor.UI.Bovespa.ContaCorrente.Communication.Bovespa.ContasCorrente.ContasCorrente;

namespace Sinacor.UI.Bovespa.ContaCorrente.Communication
{
    public class ContaCorrente : BaseCommunication
    {
        #region Construtor
        public ContaCorrente(SessionInformation session)
            : base(session)
        {

        }
        #endregion

        public ModelCollection<Model.HistoricoContaCorrente> ConsultarHistoricoContasCorrentes(Model.Parameter.FiltroHistoricoContaCorrente parameter)
        {
            IContasCorrente servico = null;
            
            ModelCollection<Sinacor.UI.Bovespa.ContaCorrente.Model.HistoricoContaCorrente> response = null;

            try
            {
                using (ServiceInstance<IContasCorrente> service = new ServiceInstance<IContasCorrente>())
                {
                    servico = service.TryGetInstance(this.Session);
                    response = (new Communication.Translator.DataContractToModel.ContaCorrente().
                        ToHistoricoContaCorrente(servico.ConsultarHistoricoContasCorrentes(new Communication.Translator.ModelToDataContract.ContaCorrente().ToFiltroHistoricoContaCorrenteRequest(parameter))));
                }
            }
            catch (Exception ex)
            {
                base.HandleFault(ex);
            }

            return response;
		}
	}
}